package de.tuberlin.dima.dkey.tmp;

import java.util.concurrent.BlockingQueue;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;

import de.tuberlin.dima.dkey.client.Client;
import de.tuberlin.dima.dkey.client.GTree;
import de.tuberlin.dima.dkey.util.GNode;

public class SimpleQuery {
	
	public static void main(String[] args) {
		
		//Set up the logging
	    BasicConfigurator.configure();
		Logger.getRootLogger().setLevel(Level.INFO);
		
		GTree query = new GTree();
	
		GNode a = query.addNewNodeWithValues("A");
		GNode b = query.addNewNodeWithValues("B");

		query.addEgdeWithValues(a, b, "x");
		
		if (query.isValid()){
			//Send it to the server
			try {
				Client client = new Client("localhost", 8080);
				
				client.query(query);
				
				BlockingQueue<String> answer = client.getReturnQueue();
				System.out.println(answer.take());
				
				client.end();


			} catch (Exception e) {
				e.printStackTrace();
			}
			
		}else{
			System.err.print("Tree is not valid");
		}	
	}
}
